import pygame
import sys

pygame.init()

size=width,height = 600,600
turtle_speed=[-4,2]
fish_speed=[-2,1]

bg=(255,255,255)
screen = pygame.display.set_mode(size)
pygame.display.set_caption('乌龟吃小鱼')

turtle = pygame.image.load('乌龟.jpg')
fish = pygame.image.load('金鱼.jpg')

turtle_position=turtle.get_rect()
fish_position=fish.get_rect()

while True :
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    turtle_position = turtle_position.move(turtle_speed)
    fish_position = fish_position.move(fish_speed)

    if turtle_position.left < 0 or turtle_position.right > width:
        turtle = pygame.transform.flip(turtle,True,False)
        turtle_speed[0] = -turtle_speed[0]
    if turtle_position.top < 0 or turtle_position.bottom > height:
        turtle_speed[1] = -turtle_speed[1]
        
    if fish_position.left < 0 or fish_position.right > width:
        fish = pygame.transform.flip(fish,True,False)
        fish_speed[0] = -fish_speed[0]
    if fish_position.top < 0 or fish_position.bottom > height:
        fish_speed[1] = -fish_speed[1]

    screen.fill(bg)
    screen.blit(turtle,turtle_position)
    screen.blit(fish,fish_position)
    pygame.display.flip()
    pygame.time.delay(10)
